package com.example.demo.service.Impl;

import com.example.demo.common.domain.CompensatoryLeavePlus;
import com.example.demo.common.domain.CompensatoryLeaveRecord;
import com.example.demo.common.domain.OutRecord;
import com.example.demo.mapper.CompensatoryLeaveRecordMapper;
import com.example.demo.service.ComLeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ComLeaveServiceImpl implements ComLeaveService {
    @Autowired
    private CompensatoryLeaveRecordMapper compensatoryLeaveRecordMapper;

    @Override
    public List<CompensatoryLeavePlus> selectAllPlus() {
        return compensatoryLeaveRecordMapper.selectAllPlus();
    }

    @Override
    public void updateGIdByPrimaryId(Integer cid, Integer gid) {
        CompensatoryLeaveRecord compensatoryLeaveRecord = compensatoryLeaveRecordMapper.selectByPrimaryKey(cid);
        compensatoryLeaveRecord.setGid(gid);
        compensatoryLeaveRecord.setCgeneralagree((short)1);
        compensatoryLeaveRecordMapper.updateByPrimaryKey(compensatoryLeaveRecord);
    }

    @Override
    public void updateDIdByPrimaryId(Integer cid, Integer did) {
        CompensatoryLeaveRecord compensatoryLeaveRecord = compensatoryLeaveRecordMapper.selectByPrimaryKey(cid);
        compensatoryLeaveRecord.setDid(did);
        compensatoryLeaveRecord.setCdeputyagree((short)1);
        compensatoryLeaveRecordMapper.updateByPrimaryKey(compensatoryLeaveRecord);
    }

    @Override
    public void updateDivIdByPrimaryId(Integer cid, Integer divid) {
        CompensatoryLeaveRecord compensatoryLeaveRecord = compensatoryLeaveRecordMapper.selectByPrimaryKey(cid);
        compensatoryLeaveRecord.setDivid(divid);
        compensatoryLeaveRecord.setCdividagree((short)1);
        compensatoryLeaveRecordMapper.updateByPrimaryKey(compensatoryLeaveRecord);
    }

    @Override
    public List<CompensatoryLeavePlus> GeneralSelectAllComLeave() {
        return compensatoryLeaveRecordMapper.GeneralSelectAllComLeave();
    }

    @Override
    public List<CompensatoryLeavePlus> DeputySelectAllComLeave() {
        return compensatoryLeaveRecordMapper.DeputySelectAllComLeave();
    }

    @Override
    public List<CompensatoryLeaveRecord> selectAll() {
        return compensatoryLeaveRecordMapper.selectByExample(null);
    }

    @Override
    public CompensatoryLeaveRecord selectByPrimaryId(Integer cid) {
        return compensatoryLeaveRecordMapper.selectByPrimaryKey(cid);
    }

    @Override
    public void insertSelective(CompensatoryLeaveRecord compensatoryLeaveRecord) {
        List<CompensatoryLeaveRecord> compensatoryLeaveRecords = compensatoryLeaveRecordMapper.selectByExample(null);
        if(compensatoryLeaveRecords.size() != 0){
            int lastcid = compensatoryLeaveRecords.get(compensatoryLeaveRecords.size()-1).getCid();
            compensatoryLeaveRecord.setCid(lastcid+1);
        }else{
            compensatoryLeaveRecord.setCid(1);
        }

        compensatoryLeaveRecordMapper.insertSelective(compensatoryLeaveRecord);
    }
}
